<template>
  <div class="headerbox">
    <el-dropdown trigger="click" @command="handleCommand">
      <span class="el-dropdown-link">
        {{ username }}<i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu slot="dropdown" class="menu">
        <el-dropdown-item command="logout">退出</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  name: "Header",
  data() {
    return {
      username: "",
    };
  },
  mounted() {
    if (this.username.length == 0) {
      let res = JSON.parse(window.sessionStorage.getItem("appadmin"));
      this.username = res.username;
    }
  },
  methods: {
    handleCommand(command) {
      if (command == "logout") {
        window.sessionStorage.removeItem("appadmin");
        this.$router.push("/login");
      }
    },
  },
};
</script>

<style scoped>
.headerbox {
  text-align: right;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.menu {
  text-align: center;
}
</style>